﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Sugar.Enties;
using HZH_Controls.Controls;
using Test.UC;
using System.Data.SqlClient;
using Seating.utils;
namespace Seating
{
    public partial class Student_Manage_From : Form
    {
        public bool IsStudent { get; set; }
        public Student_Manage_From()
        {
            InitializeComponent();
        }
        public Student_Manage_From(bool isStudent)
        {
            this.IsStudent = isStudent;
            InitializeComponent();
        }
        private void Student_Manage_From_Load(object sender, EventArgs e)
        {
            var db = new Tb_StudentManager();
            List<Tb_Student> list = new List<Tb_Student>();
            if (this.IsStudent)
            {
                this.Text = "修改个人信息";
                list = new List<Tb_Student> { db.GetById(LoginUserUtil.CurrentStudent.StudentId) };
            }
            else
            {
                list = db.GetList();
            }
            dataGridView_student.ReadOnly = false;
            dataGridView_student.DataSource = list;

            // 学号不可修改
            dataGridView_student.Columns[0].ReadOnly = true;
            // 屏蔽密码
            dataGridView_student.Columns[3].Visible = false;
        }

        private void dataGridView_student_CurrentCellDirtyStateChanged(object sender, EventArgs e)
        {
            SqlDataAdapter dtAdapter = new SqlDataAdapter();
            if (this.dataGridView_student.IsCurrentCellDirty)
            {
                //this.dataGridView_student.CommitEdit(DataGridViewDataErrorContexts.Commit);

            }

        }

        //行值变化

        private void dataGridView_student_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow dataGridViewRow = dataGridView_student.CurrentRow;
            Tb_Student student = dataGridViewRow.DataBoundItem as Tb_Student;
            Tb_StudentManager manager = new Tb_StudentManager();

            try
            {
                manager.Update(student);
            }
            catch (Exception)
            {
                MessageBox.Show("更新失败");
            }
        }

        private void dataGridView_student_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

    }
}
